package com.hejjon.core.utils;

import com.alibaba.excel.EasyExcel;
import org.apache.commons.compress.utils.Lists;

import java.io.ByteArrayOutputStream;
import java.util.List;

public class ExcelUtils {


    public static final String EXCEL_FILE_SUFFIX = ".xlsx";


    /**
     *
     * @param headerList  表头
     * @return 一个只有表头的空白 excel 文档
     */
    public static byte[] writeOnlyHeader(List<List<String>> headerList) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        EasyExcel.write(baos).head(headerList).sheet().doWrite(Lists.newArrayList());
        return baos.toByteArray();
    }


    public static <T> byte[] writeDataList(List<T> dataList, Class<T> clazz) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        EasyExcel.write(baos).head(clazz).sheet().doWrite(dataList);
        return baos.toByteArray();
    }


}
